/*
  Copyright 2011 fullkawa

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package jp.fullkawa.xnovel.connector;

import java.util.ArrayList;
import java.util.List;

import jp.fullkawa.xnovel.Scene;
import jp.fullkawa.xnovel.exception.RequireException;

/**
 * 選択肢
 * @author fullkawa
 */
public class Navigation extends Connector
{
	private String message;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public class Option {
		private String message;
		private Scene linkTo;

		public String getMessage() {
			return message;
		}
		public void setMessage(String message) {
			this.message = message;
		}
		public Scene getLinkTo() {
			return linkTo;
		}
		public void setLinkTo(Scene linkTo) {
			this.linkTo = linkTo;
		}
	}

	private List<Option> options = new ArrayList<Option>();

	public void addOption(String message, Scene linkTo) {
		Option option = new Option();
		option.setMessage(message);
		option.setLinkTo(linkTo);
		options.add(option);
	}

	public List<Option> getOptions() {
		return options;
	}

	public void setOptions(List<Option> options) {
		this.options = options;
	}

	@Override
	public String[] getTags()
	{
		List<String> tags = new ArrayList<String>();

		tags.add(super.getTag("tag.navigation.start", null));

		Object[] o1 = { this.getMessage() };
		tags.add(getIndent() + super.getTag("tag.navigation.message", o1));

		for (Option opt : this.getOptions())
		{
			if (opt.getMessage() == null || opt.getMessage().length() == 0) {
				throw new RequireException("文言の入力されていない選択肢があります。");
			}
			if (opt.getLinkTo() == null || opt.getLinkTo().getId() == null || opt.getLinkTo().getId().length() == 0) {
				throw new RequireException("移動先が設定されていない選択肢があります。");
			}
			Object[] o2 = { opt.getLinkTo().getId(), opt.getMessage() };
			tags.add(getIndent() + super.getTag("tag.navigation.option", o2));
		}

		tags.add(super.getTag("tag.navigation.end", null));

		return tags.toArray(new String[0]);
	}
}
